Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Add FastAPI support with an ASGI Middleware#105

Merged
sjs994 merged 2 commits into
google:masterfrom
artefactop:add-fastapi-support
Apr 12, 2022
Merged

Add FastAPI support with an ASGI Middleware#105
sjs994 merged 2 commits into
google:masterfrom
artefactop:add-fastapi-support

Conversation

@artefactop

Copy link
Copy Markdown
Contributor

Can be easily extensible for other ASGI frameworks.

@google-cla

google-cla Bot commented Mar 29, 2022

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@sjs994

sjs994 commented Mar 31, 2022

Copy link
Copy Markdown
Contributor

Thanks @artefactop for the PR. Will take a look.

@sjs994 sjs994 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @artefactop for the change. Apart from few comments added, looks good to me.

Comment thread python/sqlcommenter-python/google/cloud/sqlcommenter/fastapi.py
Comment thread python/sqlcommenter-python/google/cloud/sqlcommenter/fastapi.py Outdated
Comment thread python/sqlcommenter-python/google/cloud/sqlcommenter/fastapi.py Outdated
Comment thread python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/executor.py Outdated
Comment thread python/sqlcommenter-python/tests/fastapi/tests.py Outdated
@mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_fastapi_info', return_value=fastapi_info)
def test_all_data(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',framework='fastapi',route='/'*/",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to miss this one.
Although, this change looks good, wanted to give you an FYI on an existing bug in SQLAlchemy and psycopg2 sqlcommenter:

This query:

SELECT 1; /*controller='c',framework='fastapi',route='/'*/

In general a ; ends a SQL query. So, any comment added after that is not really part of that query. So, even with this change, my guess is SQL comments would not work as expected as DB will assume there are 2 queries:

  1. SELECT 1;
  2. /*controller='c',framework='fastapi',route='/'*/

I have added one small PR for psycopg2 as of now (Waiting for review) and will create another for SQLAlchemy if the approach doesn't have major concern.

@artefactop

Copy link
Copy Markdown
Contributor Author

@sjs994 should I merge this PR or you do?

@sjs994

sjs994 commented Apr 12, 2022

Copy link
Copy Markdown
Contributor

@artefactop I can do that.

@sjs994
sjs994 merged commit e1d9a49 into google:master Apr 12, 2022
@artefactop
artefactop deleted the add-fastapi-support branch July 18, 2022 10:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants